function singleNumber(nums) {
    let num = 0
    for (let index = 0; index < nums.length; index ++) {
        num ^= nums[index]
    }
    return num
}

const nums = [4,1,2,1,2]

console.log(singleNumber(nums))